package com.j.lemon.learn.basic.guawacache;

import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;

/**
 * @Author lijunjun
 * @Date 2018-12-29 10:34
 * @Description
 */
public class Test {
    public static void main(String[] args) {
        Cache<String,String> cache = CacheBuilder.newBuilder()
                .maximumSize(2)
                .build();
        cache.put("key1","value1");
        cache.put("key2","value2");
        cache.put("key3","value3");
        cache.put("key4","value4");
        //清空过期缓存
//        cache.cleanUp();

        cache.put("key5","value5");

        //清空所有缓存
//        cache.invalidateAll();
        System.out.println("第一个值：" + cache.getIfPresent("key1"));
        System.out.println("第二个值：" + cache.getIfPresent("key2"));
        System.out.println("第三个值：" + cache.getIfPresent("key3"));
        System.out.println("第四个值：" + cache.getIfPresent("key4"));
        System.out.println("第五个值：" + cache.getIfPresent("key5"));
    }
}
